package com.alen.sun.task;

import com.alen.sun.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class OrderCancellationTask {

    @Autowired
    private OrderService orderService;

    @Scheduled(cron = "0 */30 * * * ?") // 每隔30分钟触发一次
    public void cancelUnpaidOrders() {

        Boolean flag = orderService.cancelUnpaidOrders();
        if(!flag){
            log.info("未支付订单状态自动修改失败!");
        }else {
            log.info("未支付订单状态自动修改成功!");
        }
    }
}
